const express = require('express')
const app = express()
const serveFavicon = require('serve-favicon')

//定义静态路由
const staticRouter = require('./controller/statciRouter')
    //定义用户路由
const userRouter = require('./controller/userRouter')
    //定义文章路由
const articleRouter = require('./controller/articleRouter')

// 使用jwt解析密码
const passport = require('passport')
    //初始化passport
app.use(passport.initialize())
require('./model/passport')(passport)

//定义中间件
//中间件express-session解析session内容
const session = require('express-session')
app.use(session({
    secret: 'secret',
    resave: false,
    saveUninitialized: false
}))

//中间件bodyParser解析post请求
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

//图标使用+静态文件
app.use(serveFavicon(__dirname + '/favicon.ico'))
app.use(express.static('static'))

//使用模版引擎
app.engine('html', require('express-art-template'))


// 路由使用
app.use('/', staticRouter)
app.use('/api/user', userRouter)
app.use('/api/article', articleRouter)


app.listen(8080)